#include "semProCost.hpp"
#include <string.h>
#include <time.h>
proCost<int> s;
void product()
{
    while (true)
        s.push(rand() % 1000 + 1);
}
void custcom()
{
    while (true)
    {
        int ret = 0;
        s.pop(ret);
    }
}
void *enter(void *args)
{
    const char *str = (const char *)args;
    if (strcmp(str, "product") == 0)
        product();
    else
        custcom();
    return nullptr;
}
int main()
{
    srand((size_t)time(nullptr));
    pthread_t tid[6];
    pthread_create(tid + 0, nullptr, enter, (void *)"product");
    pthread_create(tid + 1, nullptr, enter, (void *)"custcom");
    pthread_create(tid + 2, nullptr, enter, (void *)"custcom");
    pthread_create(tid + 3, nullptr, enter, (void *)"custcom");
    pthread_create(tid + 4, nullptr, enter, (void *)"product");
    pthread_create(tid + 5, nullptr, enter, (void *)"product");
    pthread_join(tid[0], nullptr);
    pthread_join(tid[1], nullptr);
    pthread_join(tid[2], nullptr);
    pthread_join(tid[3], nullptr);
    pthread_join(tid[4], nullptr);
    pthread_join(tid[5], nullptr);
    cout << "回收线程成功" << endl;
    return 0;
}
